package TCP.Demo1;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

@SuppressWarnings("all")
public class TCPServer {
    public static void main(String[] args) throws IOException {
        //服务器端
        ServerSocket server = new ServerSocket(8888);
        //创建服务器对象
        Socket socket = server.accept();
        //使用获取客户端对象
        InputStream is = socket.getInputStream();
        //获取网络字节输入流


        //读取数据
        byte[] bytes = new byte[1024];
        int len = is.read(bytes);
        System.out.println(new String(bytes, 0, len));
        //打印出来获取的数据


        OutputStream os = socket.getOutputStream();
        os.write("收到谢谢".getBytes());
        //回写数据

        socket.close();
        server.close();
        //施放资源
    }
}
